
/// <reference path="Ajax.js" />
/// <reference path="jquery.js" />
/// <reference path="Utils.js" />
/// <reference path="Verification.js" />
/// <reference path="../lang/1.js" />



/* 单个表单的HTML部分 */
var Bill_Item_Html = "";
/* 页面语言编号 */
var Page_Lang = GetVal("lang", 1);
/* 可见状态列表，对象审核时常见 */
var Status_Visible_List = new Array(2, 1, 4, 5, 6, 7, 8, 9);



/* 全页面执行 */
$(function () {
    /* title 标签的强化显示 BEGIN */
    /* title 提示器的位置，默认right */
    var position = "right";
    if (Page_Lang > 10)
        position = "left";
    $(document).tooltip({
        position: {
            my: "{0} top+5".format(position),
            at: "{0} bottom".format(position)
        }
    });
    /* title 标签的强化显示 END */
});


/* 用户退出函数 */
function Admin_Quit() {
    Laoding(true)
    var ajax_url = "../ajax/Admin-Quit.ashx";
    setTimeout(function () {
        Ajax_Excute(ajax_url, null, null, function () { Laoding(false) }, function () { window.location.href = "ReturnLogin.htm?user-out"; }, null);
    }, 3000);
}

/* 订单打印 */
function SendToPrint(id) {
    window.open('Bills-View.aspx?id=' + encodeURIComponent(id), 'newwindow', 'height=440,width=770,top=200,left=400,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')
}


/* 选择所有checked */
function SelectAll() {
    $("input[name='checkbox1']").each(function () {
        $(this).attr("checked", true);
    });
    $(":checked").attr('checked', true);
}

/* 展示菜单栏 */
function Show_Menu2(ClassName) {
    //$(".MenuList").slideUp(500);
    //$("div." + ClassName).slideDown(500);
    $(".MenuList").slideUp(500);
    $("div." + ClassName).toggle(500);
}

/* 部分常用集成化的特殊处理;密码重设/举报/拉黑等等 */
function SpecialHandling(operation, obj_typ, item_id) {
    /* 显示的提示语句 */
    var content_text = Lang_DialogContent_Confirm_Text;
    switch (operation) {
        case "user_reset_password": content_text = Lang_DialogContent_Rreset_Password_Text; break;
        default: break;
    }

    art.dialog({
        title: Lang_DialogTitle,
        lock: true,
        content: content_text,
        okValue: Lang_DialogOkValue,
        cancelValue: Lang_Cannel,
        ok: function () {
            var data = { operation: operation, obj_typ: obj_typ, item_id: item_id };
            var ajax_url = "../ajax/SpecialHandling.ashx";
            Ajax_Excute(ajax_url, data, function () { Laoding(true) }, function () { Laoding(false) }, function () { Dialog(Lang_Complete) }, null)
        },
        cancel: function () { return 0; }
    });

}

/* 搜索用户 */
function SearchUser() {
    var user_id = $("#User_Id").val();
    var user_name = $("#User_Name").val();
    var now_url = window.location.href;
    var new_url = UrlRepVal(now_url, "user_id", user_id);
    var new_url = UrlRepVal(new_url, "user_name", user_name);
    window.location.href = new_url;
}

/* 删除对象 id：对象编号 ， typ 对象类型编号（参考【开发文档/文件类型.txt） */
function Del(item_id, item_type) {
    art.dialog({
        title: Lang_DialogTitle,
        lock: true,
        content: Lang_DialogContent,
        okValue: Lang_DialogOkValue,
        cancelValue: Lang_DialogCancelValue,
        ok: function () {
            var data = {
                Item_Id: item_id,
                Item_Typ: item_type
            };
            var ajax_url = "../ajax/Delete-Item.ashx";
            Ajax_Excute(ajax_url, data, null, null, function (msg) { if (msg > 0) $("#TR{0}".format(item_id)).remove(); }, null);
        },
        cancel: function () { return 0; }
    });
}

/*  */
function Show_Select_ShowMode_Area(item_id) {
    $("#ShowModeImg" + item_id).hide();
    $("#Select" + item_id).show(500);
}

function Select_ShowMode(item_id, item_typ, item_value) {
    /* 需要优化 */
    Ajax_Select_ShowMode(item_id, item_typ, item_value);
}

/* 判断是否已选 */
function IsSelect() {
    if ($("select").val() != "0")
        return true;
    else {
        Dialog(Warning_Select);
        ErrorFocus("select");
        $("select").focus();
        HideError("select");
        return false;
    }
}

function News_AddEdit(Item_Id) {
    var Item_Column = $("#Typ1_0").val();;
    var Item_Title = $("#Item_Title").val();
    var Item_Summary = $("#Item_Summary").val();
    var Item_Story = editor.html();
    var Orders = $("#Orders").val();
    var Item_Time = $("#Item_Time").val();
    var Lang = GetVal("lang", 1);
    var Item_Url = $("#Item_Url").val();
    var Maturity_Time = $("#Maturity_Time").val();
    var Property1 = $("#Property1").val();
    var Property2 = $("#Property2").val();
    var Property3 = $("#Property3").val();
    var Property4 = $("#Property4").val();
    var Property5 = $("#Property5").val();
    var Property6 = $("#Property6").val();
    var Property7 = $("#Property7").val();
    var Property8 = $("#Property8").val();
    var Property9 = $("#Property9").val();
    var Property10 = $("#Property10").val();

    /* 信息完整性验证 */
    if (!ValidateSelect("Typ1_0"))
        return false;
    if (!ValidateLength("Item_Title", 2, 320))
        return false;
    if (!ValidateReg("Item_Time", ValidateDateTime))
        return false;
    if (!ValidateReg("Maturity_Time", ValidateDateTime))
        return false;
    if (!ValidateMaxMinValue("Orders", 0, 255))
        return false;
    Item_Time = new Date(Item_Time);
    Maturity_Time = new Date(Maturity_Time);
    Item_Time = Item_Time.Format("yyyy/MM/dd hh:mm:ss");
    Maturity_Time = Maturity_Time.Format("yyyy/MM/dd hh:mm:ss");
    /* AJQX请求 */
    var data = {
        "Item_Id": Item_Id,
        "Item_Title": Item_Title,
        "Item_Summary": Item_Summary,
        "Item_Story": HTMLEncode(Item_Story),
        "Item_Column": Item_Column,
        "Orders": Orders,
        "Item_Time": Item_Time,
        "Maturity_Time": Maturity_Time,
        "Lang": Lang,
        "Item_Url": Item_Url,
        "Property1": Property1,
        "Property2": Property2,
        "Property3": Property3,
        "Property4": Property4,
        "Property5": Property5,
        "Property6": Property6,
        "Property7": Property7,
        "Property8": Property8,
        "Property9": Property9,
        "Property10": Property10
    }
    var ajax_url = "../ajax/News-AddEdit.ashx";
    Ajax_Excute(ajax_url, data, null, null, function () { window.location.href = "news.aspx?cid=" + Item_Column + "&lang=" + Lang; }, null);
}

function Videos_AddEdit(Item_Id) {

    var Item_Column = $("#Typ12_0").val();;
    var Item_Title = $("#Item_Title").val();
    var Item_Summary = $("#Item_Summary").val();
    var Item_Story = $("#Item_Story").val();
    var Orders = $("#Orders").val();
    var Item_Time = $("#Item_Time").val();
    var Lang = GetVal("lang", 1);
    var Item_Url = $("#Item_Url").val();
    var Maturity_Time = $("#Maturity_Time").val();
    var Property1 = $("#Property1").val();
    var Property2 = $("#Property2").val();
    var Property3 = $("#Property3").val();
    var Property4 = $("#Property4").val();
    var Property5 = $("#Property5").val();
    var Property6 = $("#Property6").val();
    var Property7 = $("#Property7").val();
    var Property8 = $("#Property8").val();
    var Property9 = $("#Property9").val();
    var Property10 = $("#Property10").val();


    /* 信息完整性验证 */
    if (!ValidateSelect("Typ12_0"))
        return false;
    if (!ValidateLength("Item_Title", 2, 320))
        return false;
    if (!ValidateReg("Item_Time", ValidateDateTime))
        return false;
    if (!ValidateMaxMinValue("Orders", 0, 255))
        return false;
    /* AJQX请求 */
    var url = "../ajax/Videos-AddEdit.ashx";
    var data = {
        "Item_Id": Item_Id,
        "Item_Title": Item_Title,
        "Item_Summary": Item_Summary,
        "Item_Story": Item_Story,
        "Item_Column": Item_Column,
        "Orders": Orders,
        "Item_Time": Item_Time,
        "Maturity_Time": Maturity_Time,
        "Lang": Lang,
        "Item_Url": Item_Url,
        "Property1": Property1,
        "Property2": Property2,
        "Property3": Property3,
        "Property4": Property4,
        "Property5": Property5,
        "Property6": Property6,
        "Property7": Property7,
        "Property8": Property8,
        "Property9": Property9,
        "Property10": Property10
    };
    Ajax_Excute(url, data, null, null, function () { window.location.href = "Videos.aspx?cid=" + Item_Column + "&lang=" + Lang; }, null);
}
function ShowCompleteUpImg() {
    var IsReturnLasePage = GetVal("isreturn", 0);
    $("q#file_upload").html(Lang_UpComplete)
    $("q#file_upload").show(500);

    if (IsReturnLasePage) {
        // window.location.href = returnpage;
    }
}
function ErrorFocus(selecter) {
    $(selecter).addClass("error");
    $(selecter).focus();
}
function HideError(selecter) {
    $(selecter).change(function () {
        if ($(selecter).val() != "0")
            $(selecter).removeClass("error");
    });

}

function ShowTypeEdit(id) {
    $("#Types div.small_edit").hide();
    $("#TR{0} div.small_edit".format(id)).slideDown(500);
}



/* album存储数据库 */
function AlbumAddEdit() {
    var Item_Id = GetVal("id", 0);
    var Orders = $("#Orders").val();
    var Item_Typ = $("#Typ7_0").val();
    var Item_Title = $("#Item_Title").val();
    var Item_Content = $("#Item_Content").val();
    var Lang = GetVal("lang", 1);
    var Item_fileExt = FileExt;

    /* 验证 */
    if (!ValidateSelect("Typ7_0"))
        return false;

    if (!ValidateLength("Item_Title", 2, 320))
        return false;

    if (!ValidateMaxMinValue("Orders", 0, 255))
        return false;


    var url = "../ajax/Album-AddEdit.ashx";
    var data = {
        Item_Id: Item_Id,
        Orders: Orders,
        Item_Typ: Item_Typ,
        Item_Title: Item_Title,
        create_time: Item_Time,
        Item_Content: Item_Content,
        Item_fileExt: Item_fileExt,
        Item_Lang: Lang
    };
    Ajax_Excute(url, data, null, null, function () { window.location.href = "Album.aspx?lang=" + Lang + "&cid=" + Item_Typ; }, null, null);
}



/* 管理员密码修改 */
function AdminPasswordEdit() {
    var Admin_Password = $("#Admin_Password").val();
    var Admin_Newpassword = $("#Admin_Newpassword").val();
    var Admin_Newpassword2 = $("#Admin_Newpassword_Confirm").val();
    console.log(Admin_Password + "\n" + Admin_Newpassword);
    if (Admin_Newpassword != Admin_Newpassword2) {
        Dialog(Lang_Error20);
        return false;
    }
    if (Admin_Newpassword.length < 9) {
        Dialog(Lang_Admin_passowrd_length_Error);
        return false;
    }
    if (Admin_Newpassword == Admin_Password) {
        Dialog(Lang_Error21);
        return false;
    }
    //    Ajax_AdminPasswordEdit(Admin_Password, Admin_Newpassword);
    var data = {
        Admin_Password: Admin_Password,
        Admin_New_Password: Admin_New_Password
    }
    var url = "../ajax/Admin-Password-Edit.ashx";
    Ajax_Excute(url, data, null, null, function (msg) {
        if (msg > 0) {
            Dialog(Lang_Admin_password_Complete);
            window.location.href = "ReturnLogin.htm?dt";
        } else if (msg == -1) {
            Dialog(Lang_Error19);
        } else {
            Dialog(Lang_Error + "<br>" + msg);
        }
    }, null, null);
}

function CommentReply_AddEdit(Id) {
    var Item_Lang = GetVal("lang", 1);
    var Item_Id = GetVal("id", 1);
    var Item_Content = $("#Item_Content").val();
    var data = {
        "Item_Id": Item_Id,
        "Item_Lang": Item_Lang,
        "Item_Content": Item_Content,
        "Id": Id
    };
    var ajax_url = "../ajax/Comment-Reply_AddEdit.ashx";
    Ajax_Excute(ajax_url, data, null, null, function () { window.location.href = ReturnPage; }, null);

}

function Type_Edit(Id, Item_Lang) {
    var Typ_Content = $("#Typ_Content").val();
    var Typ_Style = $("#Typ_Style").val();
    var Typ_JS = $("#Typ_JS").val();
    var Typ = GetVal("typ", 1);
    var Typ_Property1 = $("#Property1").val();
    var Typ_Property2 = $("#Property2").val();
    var Typ_Property3 = $("#Property3").val();
    var Typ_Property4 = $("#Property4").val();
    var Typ_Property5 = $("#Property5").val();
    var Typ_Property6 = $("#Property6").val();
    var Typ_Property7 = $("#Property7").val();
    var Typ_Property8 = $("#Property8").val();
    var Typ_Property9 = $("#Property9").val();
    var Typ_Property10 = $("#Property10").val();

    var data = {
        "Id": Id,
        "Typ_Content": Typ_Content,
        "Typ_Style": Typ_Style,
        "Typ_JS": Typ_JS,
        "Property1": Typ_Property1,
        "Property2": Typ_Property2,
        "Property3": Typ_Property3,
        "Property4": Typ_Property4,
        "Property5": Typ_Property5,
        "Property6": Typ_Property6,
        "Property7": Typ_Property7,
        "Property8": Typ_Property8,
        "Property9": Typ_Property9,
        "Property10": Typ_Property10
    };

    var ajax_url = "../ajax/Type-Edit.ashx";

    Ajax_Excute(ajax_url, data, null, null, function () { window.location.href = "Types.aspx?lang={0}&typ={1}".format(Item_Lang, Typ); }, null);



}



function ColumnBind(keep_url) {
    $("#Columns select").val(GetVal("cid"));
    $("#Columns select").change(function () {
        var cid = $("#Columns select").val();
        var obj_typ = GetVal("obj_typ", 1);
        var lang = GetVal("lang", 1);
        var status = GetVal("status", 0);
        var site = GetVal("site", 0);

        window.location.href = "{0}?cid={1}&lang={2}&status={3}&obj_typ={4}&site={5}".format(keep_url, cid, lang, status, obj_typ, site);
    });
}

/* 大图广告添加删除 */
function Advertisement_AddEdit(Id) {
    var Item_Title = $("#Item_Title").val();
    var Orders = $("#Orders").val();
    var Item_Url = $("#Item_Url").val();
    var Item_Lang = GetVal("lang", 1);
    var Item_Css = $("#Item_Css").val();
    var Item_Column = $("#Typ10_0").val();
    var Maturity_Time = $("#Maturity_Time").val();

    /* 验证排序 */
    if (!ValidateSelect("Typ10_0"))
        return false;
    if (!ValidateMaxMinValue("Orders", 0, 255))
        return false;
    if (!ValidateLength("Item_Title", 1, 255))
        return false;
    if (!ValidateReg("Maturity_Time", ValidateDateTime))
        return false;

    data = {
        "Item_Id": Id,
        "Orders": Orders,
        "Item_Url": Item_Url,
        "Item_Css": Item_Css,
        "Item_Lang": Item_Lang,
        "Item_Title": Item_Title,
        "Item_Column": Item_Column,
        "Item_Time": Item_Time,
        "Maturity_Time": Maturity_Time
    };

    var ajax_url = "../ajax/Advertisement-AddEdit.ashx";
    Ajax_Excute(ajax_url, data, null, null, function () { window.location.href = "Advertisement.aspx?cid=" + Item_Column + "&lang=" + Item_Lang; }, null);
}

/* 链接添加编辑 */
function Links_AddEdit(Id) {
    var Item_Title = $("#Item_Title").val();
    var Orders = $("#Orders").val();
    var Item_Url = $("#Item_Url").val();
    var Item_Lang = GetVal("lang", 1);
    var Item_Css = $("#Item_Css").val();
    var Item_Column = $("#Typ11_0").val();

    /* 验证排序 */
    if (!ValidateReg("Item_Url", ValidateUrl))
        return false;
    if (!ValidateSelect("Typ11_0"))
        return false;
    if (!ValidateMaxMinValue("Orders", 0, 255))
        return false;
    if (!ValidateLength("Item_Title", 2))
        return false;


    var data = {
        "Item_Id": Id,
        "Orders": Orders,
        "Item_Url": Item_Url,
        "Item_Css": Item_Css,
        "Item_Lang": Item_Lang,
        "Item_Title": Item_Title,
        "Item_Column": Item_Column
    }
    Ajax_Excute("../ajax/Links-AddEdit.ashx", data, null, null, function () { window.location.href = "Links.aspx?lang=" + Item_Lang; }, null);
}

function BeforeSend() {
    Dialog(Warning_Waiting);
}

function ProductAddEdit(Item_Id) {
    var Item_Name = $("#Item_Name").val();
    var Item_Price = $("#Item_Price").val();
    var Item_Introduction = editor.html();
    Item_Introduction = HTMLEncode(Item_Introduction);
    var Item_Instructions = $("#Item_Instructions").val();
    var Property1 = $("#Property1").val();
    var Property2 = $("#Property2").val();
    var Property3 = $("#Property3").val();
    var Property4 = $("#Property4").val();
    var Property5 = $("#Property5").val();
    var Orders = $("#Orders").val();
    var Item_Column = $("#Typ2_0").val();
    var Lang = GetVal("lang", 1);

    /* 验证 */
    if (!ValidateSelect("Typ2_0"))
        return false;
    if (!ValidateLength("Item_Name", 2))
        return false;
    if (!ValidateReg("Item_Price", ValidateMoney))
        return false;
    if (!ValidateMaxMinValue("Orders", 0, 255))
        return false;
    /* AJAX 请求 */
    data = {
        "Item_Id": Item_Id,
        "Item_Name": Item_Name,
        "Item_Price": Item_Price,
        "Item_Introduction": Item_Introduction,
        "Item_Instructions": Item_Instructions,
        "Property1": Property1,
        "Property2": Property2,
        "Property3": Property3,
        "Property4": Property4,
        "Property5": Property5,
        "Orders": Orders,
        "Item_Column": Item_Column,
        "Lang": Lang
    };
    var ajax_url = "../ajax/Product.AddEdit.ashx";
    Ajax_Excute(ajax_url, data, null, null, function () { window.location.href = "Product.aspx?lang={0}&cid={1}".format(Lang, Item_Column); })
}

function MenuAddEdit(Item_Id) {
    var Item_Title = $("#Item_Title").val();
    var Item_Url = $("#Item_Url").val();
    var Item_position = $("#Item_position").val();
    var Item_Introduction = $("#Item_Introduction").val();
    var Orders = $("#Orders").val();
    var Lang = GetVal("lang", 1);
    var Item_Typ = GetVal("menu_typ", 1);
    var Item_Column = GetVal("cid", 0);
    var Root_ID = GetVal("root_id", 0);
    var Object_Typ = $("#Object_Typ").val()

    if (!ValidateLength("Item_Title", 1, 80))
        return false;
    if (!ValidateMaxMinValue("Orders", 0, 255))
        return false;
    if (!ValidateMaxMinValue("Object_Typ", 0, 255))
        return false;


    /* 操作成功时返回的路径 */
    var return_page = "Menu.aspx?lang={0}&menu_typ={1}".format(Lang, Item_Typ);
    var ajax_url = "../ajax/Menu-AddEdit.ashx";
    var data = {
        "Item_Id": Item_Id,
        "Item_Title": Item_Title,
        "Item_Url": Item_Url,
        "Item_position": Item_position,
        "Item_Introduction": Item_Introduction,
        "Orders": Orders,
        "Item_Lang": Lang,
        "Item_Typ": Item_Typ,
        "Item_Column": Item_Column,
        "Root_ID": Root_ID,
        "Object_Typ": Object_Typ
    }
    Ajax_Excute(ajax_url, data, null, null, function () { window.location.href = return_page; }, null)
}

/* 动态链接静态化，参数说明：dynamic_url动态链接，extension存储的扩展名，存储路径 */
function Staticize_Full(dynamic_url, save_extension, save_folder) {
    var data = {
        "dynamic_url": dynamic_url,
        "save_folder": save_folder,
        "save_extension": save_extension
    };
    Ajax_Excute("/Staticize.ashx", data, null, null, function (msg) { Dialog(Lang_Obj_Staticize.format(1)) }, null);
}

/* 动态链接静态化,存储路径跟原链接一个目录 */
function Staticize_Default(dynamic_url) {
    var save_folder = dynamic_url.split("/")[0];
    Staticize_Full(dynamic_url, "html", save_folder);
}

/* 生成H5静态页面 */
function H5_Staticize(item_id, msg) {

    var lang = GetLang();
    if (msg == 1 || msg == 2) {
        var data = { "item_id": item_id, "page_lang": lang, "msg": msg }
        Ajax_Excute("/Staticize-h5.ashx", data, null, null, function (msg) { Dialog(Lang_Complete.format(msg)) }, null);
    }
}

/* 管理员信息编辑 */
function Admin_AddEdit(edit_mode) {
    var admin_id = $("#Admin_Id").val();
    var admin_name = $("#Admin_Name").val();
    var admin_group = $("#Typ31_0").val();
    var admin_level = $("#Admin_Level").val();
    var activation = GetCheckboxValue("#Activation");
    var ip_area = $("#IP_Area").val();
    var cookie_time = $("#Cookie_Time").val();
    var admin_remark = $("#Admin_Remark").val();
    var admin_introduction = $("#Admin_Introduction").val();
    var admin_email = $("#Admin_Email").val();
    var admin_phone = $("#Admin_Phone").val();
    var admin_office_tel = $("#Admin_Office_Tel").val();
    var page_lang = GetVal("lang", 1);

    /* 信息完整性验证 */
    if (!ValidateMaxMinValue("Admin_Id", 100, 9999))
        return false;
    if (!ValidateSelect("Typ31_0"))
        return false;
    if (!ValidateLength("Admin_Name", 2))
        return false;
    if (!ValidateMaxMinValue("Admin_Level", 0, 99))
        return false;
    if (!ValidateReg("IP_Area", ValidateIp))
        return false;

    /* 为给COOKIE验证足够的时间，和页面跳转返回相应时间，延长三秒动画显示时间 */
    var data = {
        "Edit_mode": edit_mode,
        "Obj_Admin_Id": admin_id,
        "Admin_Name": admin_name,
        "Admin_Group": admin_group,
        "Admin_Level": admin_level,
        "Activation": activation,
        "IP_Area": ip_area,
        "Cookie_Time": cookie_time,
        "Admin_Remark": admin_remark,
        "Admin_Introduction": admin_introduction,
        "Admin_Email": admin_email,
        "Admin_Phone": admin_phone,
        "Admin_Office_Tel": admin_office_tel,
        "Lang": page_lang
    }
    var ajax_url = "../ajax/Admin-AddEdit.ashx";
    Ajax_Excute(ajax_url, data, null, null, function (msg) { if (msg > 0) { window.location.href = "Admins-List.aspx?lang={0}".format(page_lang); } }, null);
}

function ShowHidePropertys() {
    $("#Propertys button").click(function () {
        $("#Propertys #Propertys_Area").toggle();
    })
}

function IssuedUse() {
    /* 验证是否已选栏目ID */
    if (!ValidateSelect("Typ1_0"))
        return false;
    var Item_Column = $("#Typ1_0").val();
    var Item_Id = GetVal("id", 0);
    var item_lang = GetVal("lang", 1);

    var ajax_url = "../ajax/Issued-Use.ashx";
    var data = {
        "item_id": Item_Id,
        "column_id": Item_Column,
        "item_lang": item_lang
    };

    Ajax_Excute(ajax_url, data, null, null, function (msg) { if (msg > 0) { window.location.href = "news.aspx?cid=" + Item_Column + "&lang=" + item_lang; } }, null);
}





function BillShowEditMode(item_id) {
    if (Bill_Item_Html.length > 1) {
        Dialog(Lang_Bill_Html_Is_Not_Null);
        return false;
    }
    Bill_Item_Html = $("#TR" + item_id).html() /* 存储原状态 */
    $("#TR" + item_id).addClass("edit_mode");
    $("#TR" + item_id + " .user_name").attr("contenteditable", "true");
    $("#TR" + item_id + " .user_address").attr("contenteditable", "true");
    $("#TR" + item_id + " .user_phone").attr("contenteditable", "true");

    $("#TR" + item_id + " .agents").html($("#Agents_Id").html());
    var agents_select_node = $("#TR" + item_id + " .agents").attr("title");
    $("#TR" + item_id + " .agents select").val(agents_select_node);

    $("#TR" + item_id + " div.btns a.hide").show();
    $("#TR" + item_id + " div.btns a.edit").hide();

    $("#TR" + item_id + " button.add").click(function () {
        ShowAddItemArea(item_id)
    });

    /* 已选择的产品进行数据调试 */
    Bill_Button_Evint(item_id);



}

/* 重置当前单子 */
function BillReset(item_id) {
    $("#TR" + item_id).html(Bill_Item_Html);
    $("#TR" + item_id).removeClass("edit_mode");
    Bill_Item_Html = "";

}

/* 显示新增产品选项 */
function ShowAddItemArea(item_id) {

    /* 编辑区域增加产品列表SELECT */
    $("#TR" + item_id + " div.add_produc_area").html($("#ProductList").html());
    $("#TR" + item_id + " div.add_produc_area").fadeIn();


    $("#TR" + item_id + " div.add_produc_area button").click(function () {
        var new_product_arr_list = new Array();
        var new_count_arr_list = new Array()
        new_product_arr_list = $("#TR" + item_id + " #ShoppingCartList").attr("data-item_list").split(','); /* 当前产品列表 */
        new_count_arr_list = $("#TR" + item_id + " #ShoppingCartList").attr("data-count_list").split(','); /* 当前产品数量列表 */
        var new_item_id = $("#TR" + item_id + " div.add_produc_area").find("select").eq(0).val();
        /* 判断数据是否已数组里面 */
        if (jQuery.inArray(new_item_id, new_product_arr_list) != "-1") {
            Dialog(Lang_Selected);
            return false;
        }

        var new_item_counts = $("#TR" + item_id + " div.add_produc_area").find("select").eq(1).val();
        var new_item_time = $("#TR" + item_id + " div.add_produc_area select.product-list-select :selected").attr("data-time").toString();
        var new_item_price = $("#TR" + item_id + " div.add_produc_area select.product-list-select :selected").attr("title").toString();
        var new_item_name = $("#TR" + item_id + " div.add_produc_area select.product-list-select :selected").attr("data-item-name").toString();
        var new_column_name = $("#TR" + item_id + " div.add_produc_area select.product-list-select :selected").attr("data-column-name").toString();
        var new_item_img = "../DataFile/Product/{0}_ssss.jpg".format(TimeToFolderName(new_item_time));


        var product_list_count = new_product_arr_list.length;
        var new_html = "<li><code class=\"item_id\">{0}</code><img  src=\"{1}\"><span>{2}<b>{3}</b></span><code class=\"price\">{4}</code><div class=\"count_control\"><button class=\"minus\">-</button><code data-item-id=\"{5}\" data-price=\"{4}\" class=\"count\">{6}</code><button class=\"plus\">+</button></div><button class=\"del\" >{7}</button></li>".format(new_item_id, new_item_img, new_item_name, new_column_name, new_item_price, item_id, new_item_counts, Lang_Del);
        $("#TR" + item_id + " #ShoppingCartList ul").append(new_html);

        allPrice(item_id);
        new_product_arr_list.push(new_item_id);
        new_count_arr_list.push(new_item_counts);
        $("#TR" + item_id + " #ShoppingCartList").attr("data-item_list", new_product_arr_list.toString()); /* 更新当前产品列表 */
        $("#TR" + item_id + " #ShoppingCartList").attr("data-count_list", new_count_arr_list.toString()); /* 更新当前产品数量列表 */

        Bill_Button_Evint(item_id);

        //    alert(new_product_arr_list + "\n" + new_count_arr_list + "\n" + new_item_img)
    });

}

function Bill_Button_Evint(item_id) {

    /* 删除事件 */
    $("#TR" + item_id + " li").delegate("button.del", "click", function () {
        var li_position = parseInt($(this).parents("li").index());
        var note_item_counts = parseInt($("#TR" + item_id + " ul").find("code.count").eq(li_position).html())
        var note_item_Price = parseFloat($("#TR" + item_id + " ul").find("code.count").eq(li_position).attr("data-price"), 2);




        /* 原数据里面删除 */
        $(this).parents("li").remove();
        /* 总额变化 */
        allPrice(item_id)



        var li_count = $("#TR" + item_id + " li").length - 1;
        var new_product_arr_list = new Array();
        var new_count_arr_list = new Array();

        for (i = 0; i < li_count; i++) {
            var new_item_id = $("#TR" + item_id + " li").find("code.item_id").eq(i).html();
            var new_item_count = $("#TR" + item_id + " li").find("code.count").eq(i).html();
            new_product_arr_list.push(new_item_id);
            new_count_arr_list.push(new_item_count);
        }

        $("#TR" + item_id + " #ShoppingCartList").attr("data-item_list", new_product_arr_list.toString()); /* 更新当前产品列表 */
        $("#TR" + item_id + " #ShoppingCartList").attr("data-count_list", new_count_arr_list.toString()); /* 更新当前产品数量列表 */


    });



    /* 增加减小产品数量事件 */
    $("#TR" + item_id + " li div.count_control").delegate("button.minus", "click", function () {
        $(this).next().html(grantedCount($(this).next().html(), -1));
        /* 总额变化 */
        allPrice(item_id)


    });
    $("#TR" + item_id + " li div.count_control").delegate("button.plus", "click", function () {
        $(this).prev().html(grantedCount($(this).prev().html(), 1));
        /* 总额变化 */
        allPrice(item_id)
    });
}

/* 计算当前单子的总额 */
function grantedCount(count, number, item_price, all_price_position_id) {

    var newValue = parseInt(count) + number;
    if (newValue < 1) {
        return 1;
    }
    else if (newValue > 20) {
        return 20;
    }
    return newValue;
}

function allPrice(item_id) {
    var li_count = $("#TR" + item_id + " li").length;
    var newValue = 0;
    for (i = 0; i < li_count; i++) {
        var new_item_price = parseFloat($("#TR" + item_id + " li").find("code.price").eq(i).html(), 2);
        var new_item_count = parseInt($("#TR" + item_id + " li").find("code.count").eq(i).html());
        newValue = newValue + (new_item_price * new_item_count);
    }

    $("#TR" + item_id + " code.all_price").hide();
    $("#TR" + item_id + " code.all_price").html(newValue.toFixed(2));
    $("#TR" + item_id + " code.all_price").fadeIn();
    return newValue;
}


function SaveBillItems(item_id) {
    var li_count = $("#TR" + item_id + " li").length;
    var new_product_arr_list = new Array();
    var new_count_arr_list = new Array();

    for (i = 0; i < li_count; i++) {
        var new_item_id = $("#TR" + item_id + " li").find("code.item_id").eq(i).html();
        var new_item_count = $("#TR" + item_id + " li").find("code.count").eq(i).html();
        new_product_arr_list.push(new_item_id);
        new_count_arr_list.push(new_item_count);
    }

    var user_name = $("#TR" + item_id + " td.user_name").html();
    var user_phone = $("#TR" + item_id + " code.user_phone").html();
    var user_address = $("#TR" + item_id + " td.user_address").html();
    var agents = $("#TR" + item_id + " td.agents select").val();
    var item_lang = GetVal("lang", 1);
    var all_price = $("#TR" + item_id + " code.all_price").html();
    var bill_status = $("#TR" + item_id + " td.work_flow select").val();
    /* 数据验证 */
    if (li_count < 1) {
        Dialog(Lang_Shopping_Cart_Null)
        return false;
    }
    alert(new_product_arr_list + "\n" + li_count)
    /* 数据提交 */
    jQuery.ajax({
        url: "../ajax/Product_Bill_Edit.ashx",
        type: "post",
        cache: "false",
        data: {
            "Bill_Id": item_id,
            "Bill_User_Name": user_name,
            "Bill_User_Phone": user_phone,
            "Bill_User_Address": user_address,
            "Bill_SendShops": agents,
            "Bill_Product_List": new_product_arr_list.toString(),
            "Bill_Count_List": new_count_arr_list.toString(),
            "item_lang": item_lang,
            "Bill_Price": all_price,
            "Bill_Status": bill_status,
            "Bill_Inquiry_Id": 0
        },
        dataType: "text",
        success: function (msg) { alert(msg) }
    });
}

function jcropLaod() {




    img_p_width = parseInt($('#preview').css("width").replace("px", "")); /* 原始图片宽度 */
    img_p_height = parseInt($('#preview').css("height").replace("px", "")); /* 原始图片高度 */

    /* 初始化 */
    Bulid_Size(16, 9)



    /*可视化编辑区生成 判断图片是长图还是宽图 */
    if (img_p_width > img_p_height)
        $('#jcrop_target').css("max-width", "100%");
    else
        $('#jcrop_target').css("max-height", "580px");

    img_b_width = parseInt($('#jcrop_target').css("width").replace("px", "")); /* 显示区域的图片宽度 */
    img_b_height = parseInt($('#jcrop_target').css("height").replace("px", "")); /* 显示区域的图片高度 */


    /* 如果图片宽度大于选择区域的图片的宽度，进行比列计算 */
    if (img_p_width > img_b_width) {
        ratio_width = img_b_width / img_p_width;
        ratio_height = img_b_height / img_p_height;

    }

    // alert(img_p_width + "\n" + img_p_height + "\n" + img_b_width + "\n" + img_b_height + "\n W比列:" + ratio_width + "\n H比列:" + ratio_height);


    $(function () {
        $('#jcrop_target').Jcrop({
            onChange: showCoords,
            onSelect: showCoords,
            aspectRatio: 16 / 9
        }, function () {
            jcrop_api = this;
        });
    });
}

function showCoords(c) {
    updatePreview(c)
    $('#x1').val(Math.round(c.x / ratio_width));
    $('#y1').val(Math.round(c.y / ratio_height));
    $('#x2').val(Math.round(c.x2));
    $('#y2').val(Math.round(c.y2));
    $('#w').val(Math.round(c.w / ratio_width));
    $('#h').val(Math.round(c.h / ratio_height));

};

/* 预览图更新 */
function updatePreview(c) {
    if (parseInt(c.w) > 0) {
        var rx = 320 / c.w;
        var ry = 180 / c.h;

        $("#preview").css("width", Math.round(rx * img_b_width));
        $("#preview").css("height", Math.round(rx * img_b_height));
        $("#preview").css("margin-left", 0 - Math.round(rx * c.x));
        $("#preview").css("margin-top", 0 - Math.round(rx * c.y));
    }
}
/* 比列调整 执行页面[admincenter/Ploting.aspx] */
$("#Set_Area").delegate("button", "click", function (e) {

    var mew_ratio = $(this).attr("data-value");
    var node_status = parseInt($(this).attr("data-status"));

    mew_ratio = mew_ratio.split("/");
    if (node_status == 1) {
        jcrop_api.setOptions({ aspectRatio: parseInt(mew_ratio[0]) / parseInt(mew_ratio[1]) });
        Bulid_Size(parseInt(mew_ratio[0]), parseInt(mew_ratio[1]));
        $(this).attr("data-status", 0);
    }
    else {
        jcrop_api.setOptions({ aspectRatio: parseInt(mew_ratio[1]) / parseInt(mew_ratio[0]) });
        Bulid_Size(parseInt(mew_ratio[1]), parseInt(mew_ratio[0]));
        $(this).attr("data-status", 1);
    }

    jcrop_api.focus();
});




/* 提交生成缩略图，参数来于HTML页面，参数来源页面[admincenter/Ploting.aspx] */
function BuildThumbnail() {
    var x1, x2, y1, y2, width, height, imgPath, list_str;
    x1 = $('#x1').val();
    x2 = $('#x2').val();
    y1 = $('#y1').val();
    y2 = $('#y2').val();
    width = $('#w').val();
    height = $('#h').val();
    imgPath = $("#jcrop_target").attr("src");
    /* 要生成的缩略图列表 */
    var Select_Size_List = new Array();
    $("input[name='Size_item']:checkbox").each(function () {
        if ($(this).is(':checked')) {
            Select_Size_List.push($(this).val())
        }
    })
    
    /* 判断是否空对象 */
    if (Select_Size_List.length < 1) {
        window.location.href = returnpage
        return;
    }
    var url = "../ajax/Build-thumbnail.ashx";
    /* 操作完成时 */
    var right = function () {
        window.location.href = returnpage
    };
    var data = {
        "imgPath": imgPath,
        "x1": x1,
        "x2": x2,
        "y1": y1,
        "y2": y2,
        "width": width,
        "height": height,
        "img_b_width": img_b_width,
        "img_b_height": img_b_height,
        "select_size_list": Select_Size_List.toString()
    };

    Ajax_Excute(url, data, null, null, right, null);


}


/* 缩略图列表生成函数，按宽度和比例生成缩略图列表 */
function Bulid_Size(width, height) {

    var item_size_count = $("#Size_list span.w").length;
    var i = 0;
    while (i < item_size_count) {
        var obj_width = parseInt($("#Size_list span.w:eq(" + i + ")").html());
        var new_height = Math.round(height / width * obj_width);
        if (i == 0)
            $(".pri320").css("height", new_height)
        $("#Size_list input:eq(" + i + ")").attr("title", obj_width + "*" + new_height);
        $("#Size_list input:eq(" + i + ")").val(obj_width + "*" + new_height);
        $("#Size_list span.h:eq(" + i + ")").html(new_height)
        i++;
    }

}
/*
栏目增加, 可以一次增加多个栏目，按换行分别
type_names 栏目昵称列表，item_lang语言编号，r_id上级目录ID ，obj_type 对象编号(参考~/开发文档/文件类型.txt)
*/
function Type_Add() {
    var item_lang = GetVal("lang", 1);
    var root_id = GetVal("rid", 0);
    var obj_type = GetVal("typ", 1);

    var type_names = $("#TypNames").val();
    if (type_names && type_names.trim().length > 0) {
        var data = {
            "item_lang": item_lang,
            "r_id": root_id,
            "obj_type": obj_type,
            "type_name": type_names,
        };
        var ajax_url = "../ajax/Type-Add.ashx";
        Ajax_Excute(ajax_url, data, null, null, function () { window.location.href = "types.aspx?lang={0}&typ={1}&time=now".format(item_lang, obj_type) }, null);
    }
    else
        Dialog(Lang_Error1)
}

function EditTypName(column_id) {
    var name = $("#Name{0}".format(column_id)).val();
    var order = $("#orders{0}".format(column_id)).val();
    /* 验证 */
    if (!ValidateLength("Name{0}".format(column_id), 1, 150))
        return false;
    if (!ValidateMaxMinValue("orders{0}".format(column_id), 0, 255))
        return false;

    var url = "../ajax/Type.Edit.Name.ashx";
    var data = { Id: column_id, Name: name, Orders: order };
    Ajax_Excute(url, data, null, null, function () { $("#TR{0}  span.name".format(column_id)).html(name); $("#TR{0} code".format(column_id)).html(order); $("#TR{0} div.small_edit".format(column_id)).slideUp(); }, null);

}


function CSS3_AnimationStyle_AddEdit(Style_Id) {

    var Style_Column = $("#Typ23_0").val();
    var Style_Lang = GetVal("lang", 1);
    var Style_Name = $("#Style_Name").val();
    var Style_Countent = $("#Style_Countent").val();
    var Style_Order = $("#Style_Order").val();
    var Activation = GetCheckboxValue("#Activation");
    var Style_Animation_Name = $("#Style_Animation_Name").val();
    var Style_Default = $("#Style_Default").val();
    var data = {
        "Style_Id": Style_Id,
        "Style_Name": Style_Name,
        "Style_Countent": Style_Countent,
        "Style_Lang": Style_Lang,
        "Style_Order": Style_Order,
        "Style_Status": Activation,
        "Style_Column": Style_Column,
        "Style_Animation_Name": Style_Animation_Name,
        "Style_Default": Style_Default
    }
    var Ajax_URL = "/ajax/CSS3-AnimationStyle-AddEdit.ashx";
    Ajax_Excute(Ajax_URL, data, function () { }, function () { }, function (msg) { window.location.href = "/AdminCenter/CSS3-AnimationStyle.aspx?lang=" + Style_Lang; }, null);
}

function Approved(item_id, item_typ, item_status) {
    var ajax_url = "../ajax/Approved-Item.ashx";
    var data = {
        "item_id": item_id,
        "item_typ": item_typ,
        "item_status": item_status
    }
    Ajax_Excute(
        ajax_url,
        data,
        function () {
            $("#Select" + item_id).hide();
            $("#ShowModeImg" + item_id).show();
            $("#ShowModeImg" + item_id).attr("src", "../static/img/laodinghome.gif");
        },
        null,
        function (msg) {
            /*如果是H5的审核生产静态页面*/
            if (item_typ == 19)
                ApprovedMicroYurnalEvent(msg, item_id);
            $("#ShowModeImg" + item_id).hide();
            $("#ShowModeImg" + item_id).attr("src", "../static/img/show-mode-" + msg + ".png");
            $("#ShowModeImg" + item_id).fadeIn();
        },
        null)
}

/*如果是H5的审核生产静态页面*/
function ApprovedMicroYurnalEvent(msg, item_id) {

    if (Status_Visible_List.indexOf(parseInt(msg), 0) > -1) {
        H5_Staticize(item_id, msg);
    }
}


/*提示信息添加或修改模块*/
function Alert_AddEdit(id) {
    var Ar_text = $("#Ar_Text").val();
    var lang = GetVal("lang", 1);
    var url = "/ajax/Alert-AddEdit.ashx";
    var data = { "Ar_text": Ar_text, "Ar_Id": id, "Ar_Lang": lang };
    Ajax_Excute(url, data, null, null, function (msg) { alert(msg)}, null);
}

/* 显示所有生成的缩略图 */
function ViewCoverImglist() {
    window.open("Ploting-View.aspx?lang={0}&img_time={1}&cover_foolder={2}".format(GetVal("lang"), Item_Time, CoverFoolder));
}